<?php
namespace App\Http\Controllers\Api\V5;
use Illuminate\Http\Request;
use Validator;
use App\Http\Controllers\Controller;
use App\Models\V5\AudioModel;
use App\Common\ApiData;



class AudioController extends Controller{


    /**
     * 音频分页
     * */
    public function page_audio(Request $request)
    {
        $userId     = $request->input('tokenUserId',0);
        $audioModel = new AudioModel();
        $audioList  = $audioModel->get_audio_list($userId);

        foreach ($audioList as $audio) {
            $params = [
                'audioId'  => $audio->AudioID,
                'parentId' => 0
            ];
            $params = http_build_query($params);

            $shareInfo        = [
                'title'       => "老侯论道",
                'groupTitle'  => $audio->AudioTitle,
                'description' => $audio->AudioTitle,
                'img'         => env('ADMIN_HOST') . "/images/default-images/share-mp3.png",
                'link'        => env('ADMIN_HOST') . "/home/audio_share_to_weixin?" . $params,
                "audio"       => $audio->FilePath1,
            ];
            $audio->shareInfo = $shareInfo;
        }

        $apiData = new ApiData();

        return $apiData->set_data('data', $audioList)->send_old(200, 'ok');
    }




    /**
     * 记录浏览次数
     * */
    public function record_view_times(Request $request){
        $audioId    = $request->input('audioId');
        $audioModel = new AudioModel();
        $audioModel->add_audio_view_times($audioId);
        $apiData    = new ApiData();
        $apiData->message   = "ok";
        $apiData->code      = 200;
        return $apiData->send();
    }


    /**
     * 收集老侯论道音频
     * */
    public function collect_lundao(Request $request)
    {

        $userId     = $request->input('tokenUserId');
        $audioId    = $request->input('audioId',0);
        $rules      = [
            'tokenUserId'   => [$userId,"缺少用户ID"],
            'userId'        => [$audioId,"缺少音频ID"]
        ];
        $res = $this->check_params($rules);
        if($res->status == false)
        {
            return apiData()->send(3001,$res->message);
        }
        AudioModel::collect_video($userId,$audioId);
        return apiData()->send(200,'ok');
    }


    /**
     * 打赏列表
     * */
    public function rewards(Request $request)
    {
        $audioId    = '';
    }

}